implements the specific product of the Iuser interface. A class that accesses the user table of an Access database.public class Accessuser implements Iuser {@Overridepublic void Insert (user user) {System.out.println ("Accessuser insert U Ser ");} @Overridepublic void getUser (int id) {System.out.println ("Accessuser get User");}}Ifactory interface, abstract factory, defines an abstract factory interface that creates access to user table objects.Publ
Turn: http://blog.csdn.net/zhengzhb/article/details/7348707
--------------------------------------
Definition:Defines an interface used to create objects so that the subclass determines which class to instantiate. The factory method delays the instantiation of a class to its subclass.
Type:Create Class Mode
Class diagram:
Factory method mode code
[Java]View plaincopyprint?
Interface iproduct {
Public void productmethod ();
}
Class product implements iproduct {
Public void productmethod
the same interface as the real object, so it can represent the real object at any time. The agent role contains a reference to the real object, so she can manipulate the real object and attach other actions, which is equivalent to encapsulating the real object.
Realsubject: Real role. It represents the real object, the object that we end up referencing.
Example:If you have a factory that starts with a cell phone, but it doesn't want to make it itself now, it's handing over its own stuff
The factory method pattern differs from the simple factory pattern in that the factory method pattern places the object creation process into the lining class. This way the factory parent object, like the product parent object, can be an abstract class or interface that defines only the appropriate specification or operation, and does not involve specific creation or implementation details.Its class diagram is as follows:
The instance code is:
#pragma once
class iproduct
{public
:
System; using System.Collections.Generic; using System.Linq
;
Using System.Text; namespace Productenity {///
Using Factoryentiy;
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace productenity
{
///
3. Consider, under what circumstances, the creation of a store entity, rent calculations for different stores, and facilitate subsequent additions and modifications. So we created the Ifactroy interface, which is the way to create the
Original: http://www.codeceo.com/article/23-design-parttens-factory-partten.htmldefinition: defines an interface that is used to create an object, so that subclasses decide which class to instantiate, and the factory method defers the instantiation of a class to its subclasses.Type: Create class ModeClass Diagram:Factory Method Pattern CodeInterface IProduct {public void Productmethod ();} Class Product implements IProduct {public void Productmethod () {System.out.println ("Product");}} Interfac
product class:/** * Product Abstraction * * @author Ice_melt * */public abstract class Abstractproduct {public abstractproduct () {}//All products have a way to show it externally public abstract void display (); Three products in the basic abstract product Category:Products--car public class Carproduct extends Abstractproduct {@Overridepublic void display () {System.out.println ("I have four wheels, Running fast on Land ");}}Product--Aircraft public class Airplaneproduct extends Abstractprod
Definition: Defines an interface for creating objects, letting subclasses decide which class to instantiate, and the factory method delays the instantiation of a class to its subclasses.Type: Creating class ModeClass Diagram:
Factory Method mode Code
Interface IProduct {public
void Productmethod ();
}
Class Product implements IProduct {public
void Productmethod () {
System.out.println ("Product");
}
}
Interface Ifactory
method for creating objects. Subclasses implement this method to create objects of a specific type.Some of the procedures in object creation include deciding which objects to create, managing the life cycle of objects, and managing the creation and destruction of specific objects.2 from theory to realityThe Mediaplayerfactory in Android is the classic simple factory model, which is defined as:Class Mediaplayerfactory {public:class ifactory {... };
WaterA frog is laughing.--Stone and waterFactory method Mode (Factory), which defines an interface for creating objects, letting the implementation class decide which class to instantiate. The factory method defers the instantiation of a class to its subclasses.Here we write the factory on the basis of simple and factory:Define an interface first1 Package Cn.no5.factorymethod; 2 3 import cn.no1.simplefactory.Operation; 4 5 Public Interface ifactory {
, function does not support and so on. Please design a set of programs to achieve seamless data migration. Brief Introduction
By using our factory method model, we have better solve the problem that users use different databases, now we have obtained the database object to create, then we need to add the data to the database, assuming all need to add department information, some users need to use Oracle, Some users need to use SQL Server. Consider the code structure of the abstract factory patte
See a few times the abstract Factory mode, each view needs to be re-understood, it may be involved in a number of classes and interfaces, so more difficult to clear the relationship it! As far as I'm concerned, we still have to learn from our thoughts rather than mechanically.Look at the class diagram:Liar design mode-Class diagramLook at the class diagram has been very chaotic, to simply comb under. We only look at the interface, so it is not difficult to see that the abstract factory is actual
size of your phone /**@author*/publicabstract class Applephone { /** * Get size * / protected Abstract void getsize ();}Different models of "mobile phones" for Apple phones/*** Iphone4 *@authorSONGWZ **/ Public classIphone4extendsapplephone{@Override Public voidGetSize () {System.out.println ("IPhone4 Screen: 3.5 inch"); }}/*** IPhone5 *@authorgt780 **/ Public classIphone5extendsApplephone {@Override Public voidGetSize () {System.out.println ("IPhone5 Screen: 4 inch"); }}/*** I
a specific class.Features: Compared to the factory model, there can be more than one entry, and there are various types of returns. The following example returns two types, B, which are not unique to the abstract class, so use an interface to implementFactory interface Package note.com.factory; Import Note.com.bean.a; Import note.com.bean.b; Public Interface ifactory { public A geta (); Public B Getb ();}Factory Implementation Class 1 P
Definition: Defines an interface that is used to create an object, so that subclasses decide which class to instantiate, and the factory method defers the instantiation of a class to its subclasses.Type: Create class modeClass Diagram:Factory Method Pattern CodeInterfaceiproduct {public void Productmethod (); }ClassProductImplementsiproduct {public void Productmethod () {System.out.println ( "products"); }} interface IFactory {public iproduct createpr
Design pattern--Abstract Factory mode1, definition: Provide an interface that creates a series of related or interdependent objects without having to develop their specific classes;2, the following is a schematic diagram of the abstract factory pattern:3, the implementation code of the Abstract factory pattern:1), Structure diagram: 2), CodeEntry Class Main.class:public class Main {Public static void Main (string[] args) { Breadmaker Breadmaker;Pizzamaker Pizzamaker;System.out.println ("Openin
Factory)Four roles are involved: Abstract Factory roles, specific factory roles, abstract product roles, and specific product roles.Abstract Factory roles use interfaces or parent classes to describe factory behaviors,A specific factory role is responsible for creating a certain type of product objects.Abstract product classes can use interfaces or parent classes to describe the behavior characteristics of product objects.A specific product class is a specific object.
The factory mode is differe
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.